package com.taotao.web.rabbit;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.taotao.common.service.RedisService;

public class ItemListener {
	
	private static final ObjectMapper MAPPER = new ObjectMapper();
	
	@Value("${TAOTAO_WEB_ITEM_CACHE_PREFIX}")
	private String TAOTAO_WEB_ITEM_CACHE_PREFIX;
	
	@Value("${TAOTAO_WEB_ITEM_DESC_CACHE_PREFIX}")
	private String TAOTAO_WEB_ITEM_DESC_CACHE_PREFIX;
	
	@Autowired
	private RedisService redisService;

	public void listen(String msg){
		long itemId = 0l;
		try {
			JsonNode jsonNode = MAPPER.readTree(msg);
			itemId = jsonNode.get("id").asLong();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		this.redisService.del(TAOTAO_WEB_ITEM_CACHE_PREFIX + itemId);
		this.redisService.del(TAOTAO_WEB_ITEM_DESC_CACHE_PREFIX + itemId);
	}
}
